#include <stdio.h>

#define STDIN
//#define DEBUG

int a, b, c, d, e,f;
int need11 = 0;
int need22 = 0;
int sum = 0;
int x22[] = {0, 5, 3, 1};

int main()
{
#ifdef STDIN
    freopen("bin/1017.in", "r", stdin);
#endif

    while(1)
    {
        scanf("%d %d %d %d %d %d", &f, &e, &d, &c, &b, &a);
        if ((a|b|c|d|e|f) == 0)
        {
            break;
        }

        sum = 0;
        need11 = 0;
        need22 = 0;

        sum = a + b + c + (d+3)/4;

        need22 = c*5 + x22[d%4];

        if (e > need22)
        {
            sum += (e - need22 + 8) / 9;
        }

        need11 = sum * 36 - a*36 - b*25 - c*16 - d*9 - e*4;

        if (f > need11)
            sum += (f -need11 + 35)/36;

        printf("%d\n", sum);
    }
    return 0;
}
